import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

/**
 * This class creates the user. It takes in the UserName and password
 * and a boolean to tell weather the user is locked out or not. There
 * are four roles (doc, nurse, patient, system admin). Determines the 
 * current role of the person logging in. Pulls in patient information 
 * and has a record for how many attempts the user has tried to log in. 
 * 
 * @author evelyn942
 * @version 1.0 3-10-11
 */


public class User {
	
	private static final int numRoles = 4;

    private String userName, password;
    
    private boolean suspended;
    
    private boolean[] roles;
    
    /**
     * This class is used in determining the current role of the user. 
     */
    private Role currentRole; 
    
    /**
     * The variable info is an instance of PatitientInformation. If the user is a patieint, then it will access this to make a new
     * patient information section. 
     */
    private PatientInformation info;
    
    private int ssn;
    /**
     * This constructor takes in no variables. It sets up the info, roles, and suspended to create a new user. It creates info 
     * (PatientInformation) for all users, it creates an array of booleans of length four (patient, nurse, doc, system admin)
     * and tells weather they are suspended from their account. 
     */
    public User(){
    	info = new PatientInformation();
    	roles = new boolean[numRoles];
    	suspended = false;
    }
    /**
     * This constructor takes in four variables to set up the user. It creates a name, password for the account, boolean array 
     * to determine what kind of user (patient, nurse, doc, system admin), and a social security number. All this will be used
     * by other classes and for storage in the database. 
     * @param userName Creates a string for the userName
     * @param password Creates a string for the password
     * @param roles Creates a boolean array of roles which is copied from the roles class
     * @param ssn creates an int for the social security number
     */
    public User(String userName, String password, boolean[] roles, int ssn){
    	this();
    	this.userName = userName;
    	this.password = password;
    	if(roles.length <= this.roles.length){
    		System.arraycopy(roles, 0, this.roles, 0, roles.length);
    	}
    	this.ssn = ssn;
    }
    /**
     * This method adds a treatment record via the TreatmentRecord addTreatmentRecord method. It takes in a parameter of type 
     * TreatmentRecord and adds it to the front of the que for that particular patient   
     * @param tr Adds a treatmentRecord to the front of the treatmentRecord list
     */
    public void addTreatmentRecord(TreatmentRecord tr){
    	info.addTreatmentRecord(tr);
    }
    /**
     * This toString method returns a long string of the username, password, and suspspende boolean. This information will be available
     * to all classes and the database.
     * @return Returns a long string of information from this class that can be accessable by everyone
     */
    public String toString(){
    	return "USER/n User Name" + this.getUserName() + 
    	"/n Password" + this.getPassword() + 
    	"/n Password Suspended" + this.getSuspended();
    }
    
/**
 * General getters and setters
 */
    
    /**
     * This setter takes in an int and sets the SSN
     * @param ssn This paramater is of type int and is used to set the SSN
     */
    public void setSSN(int ssn){
    	this.ssn = ssn;
    }
    /**
     * This getter gets the SSN 
     * @return returns the ssn in a type int 
     */
    public int getSSN(){
    	return ssn;
    }
    /**
     * This setter takes in a string and sets it to the userName
     * @param userName Is a type string and is set to the userName
     */
    public void setUserName(String userName){
                this.userName = userName;
    }
    /**
     * This getter gets the userName and returns it as a string.
     * @return userName Returns the username as a string for all other classes to use
     */
    public String getUserName(){
        return userName;
    }
    /**
     * This setter takes in a string and sets the password
     * @param password Taken in as a string and sets the password
     */
    public void setPassword(String password){
                this.password = password;
    }
    /**
     * This getter gets the password of the user and returns it as a string for access by other classes
     * @return password. Returns the password as a string for access by other classes
     */
    public String getPassword(){
        return password;
    }
    /**
     * This setter sets weather or not the account is suspended because the user has tried to log in too many times. 
     * @param suspended Takes in a boolean (originally false saying the account isn't suspended) and sets the state of users account
     */
    public void setSuspended(boolean suspended){
        this.suspended = suspended; 
    }
    /**
     * This getter gets the state of the users account (false = not suspended, true = suspended)
     * @return suspended Gets the state of the users account and returns as a boolean for use by all classes 
     */
    public boolean getSuspended(){
        return suspended;
    }
    /**
     * This getter gets the boolean array and determines what role (patient, nurse, doctor, syst admin) the user is. 
     * @return roles Returns as a type boolean array for access by all other classes
     */
    public boolean[] getRoles(){
    	return roles;
    }
    /**
     * This setter sets the role of the user by taking in a boolean array (ex: [ F F T F] ) 
     * @param roles This parameter is a boolean array that sets the role of the user
     */
    public void setRoles(boolean[] roles){
    	if(this.roles.length == roles.length){
    		System.arraycopy(roles, 0, this.roles, 0, roles.length);
    	}
    }
    
/**
 * getters for trickle down- all the getters to access stuff in PatientInformation class
 */
    /**
     * This getter uses the PatientInformation's getName to access the name of the patient. 
     * @return Returns the name of the patient from the patient information class and uses PatientInformation's getName method 
     */
    public String getName(){
        return info.getName();
    }
    /**
     * This setter takes in a string and sets the name of the patient through the PatientInformation setName function
     * @param name Takes in a string to set the name of the patient via the PatientInformation class 
     */
    public void setName(String name){
        info.setName(name);
    }
    /**
     * This getter gets the address of a patient via the PatientInformation getAddress method for access by other classes 
     * @return Returns the address of a patient for use by other classes via the PatientInformation getAddress class
     */
    public String getAddress(){
        return info.getAddress();
    }
    /**
     * This method sets the address of the patient via the PatientInformation setAddress method
     * @param address Takes in a string to set the address of the patient via the PatientInformation setAddress method
     */
    public void setAddress(String address){
        info.setAddress(address);
    }
    /**
     * This getter gets the phone number of a patient via the PatientInformation getPhone method 
     * @return Returns the patients phone number vai the PatientInformation getPhone method and allows access by all classes
     */
    public String getPhone(){
        return info.getPhone();
    }
    /**
     * This setter sets the phone number by taking a string
     * @param phone Parameter of type string taken in and used to set the phone number via the PatientInformation setPhone method 
     */
    public void setPhone(String phone){
        info.setPhone(phone);
    }
    /**
     * This method gets the email of a patient via the PatientInformation getEmail method
     * @return Returns the email of the patient in the form of a string via the PatientInformation getEmail method
     */
    public String getEmail(){
        return info.getEmail();
    }
    /**
     * This setter sets the email by taking a string and using the PatientInformation setEmail method
     * @param email Takes in a string parameter and uses the PatientInformation setEmail method to set the email
     */
    public void setEmail(String email){
        info.setEmail(email);
    }
    /**
     * This method gets the Patients pharmacy by using the PatientInformation's getPharmacy method and allows access for other classes
     * @return Returns a string of the pharmacy for the patient using the PatientInformation getPharmacy method
     */
    public String getPharmacy(){
        return info.getPharmacy();
    }
    /**
     * This method sets the Pharmacy for a patient by taking in a string and using the PatientInformation setPharmacy method
     * @param pharmacy Takes in a parameter of type String and sets the Pharmacy using the PantientInformation setPharmacy method
     */
    public void setPharmacy(String pharmacy){
        info.setPharmacy(pharmacy);
    }
    /**
     * This method gets the insurance of the patient and returns it in a string type
     * @return Returns the insurance of the patient in the form of a string by using the PatientInformation getInsurance method 
     */
    public String getInsurance(){
        return info.getInsurance();
    }
    /**
     * This method sets the insurance of a patient by taking in a variable of type string
     * @param insurance Takes in this parameter of type string and sets the Insurance via the PatientInformation setInsurance method
     */
    public void setInsurance(String insurance){
        info.setInsurance(insurance);
    }
    /**
     * This method gets the cell phone of a patient by using the PatientInformation getCellPhone method
     * @return Returns a string of the cell phone of a patient by using the PatientInformation getCellPhone method
     */
    public String getCellPhone(){
        return info.getCellPhone();
    }
    /**
     * This method sets the cell phone of a patient by using the setCellPhone method of the PatientInformation class
     * @param cellPhone Takes in a string to set the cell phone
     */
    public void setCellPhone(String cellPhone){
        info.setCellPhone(cellPhone);
    }
    /**
     * This getter gets the gender of the patient by using the PatientInformation getGender method
     * @return Returns the gender of type Gender of the patient via PatientInformation getGender method
     */
    public Gender getGender(){
        return info.getGender();
    }
    /**
     * This method takes in a variable of type Gender to set the gender of the patient using the PatientInformation class
     * @param gender Takes in this vairiable of type Gender and sets the gender of the patient 
     */
    public void setGender(Gender gender){
        info.setGender(gender);
    }
    /**
     * This method returns the DOB using the PatientInformation class getBirthDate method
     * @return Returns patient DOB in type Date by using the PatientInformation getBirthDate method
     */
    public Date getBirthDate(){
        return info.getBirthDate();
    }
    /**
     * This method takes in a variable of type Date and sets the patient's DOB
     * @param birthDate Takes in variable of type Date and sets the patients DOB using the PatientInformation setBirthDate method
     * @return 
     */
    public void setBirthDate(Date birthDate){
        info.setBirthDate(birthDate);
    }
    /**
     * This method gets the patient's allergies and returns a string
     * @return Returns the patients allergies by using the PatientInformation's getAllergies method 
     */
    public String getAllergies(){
        return info.getAllergies();
    }
    /**
     * This method takes in a string to set the allergies of a patient.
     * @param allergies Takes in this paramter of type string to set the patient's allergies using PatientInformation setAllergy method
     */
    public void setAllergies(String allergies){
        info.setAllergies(allergies);
    }
       
/**
 * Other getters and setters
 */
   /**
    * This method gets the patientInformation of this class and returns it of type PatientInfomration
    * @return Returns the PatientInformation of this class 
    */
    public PatientInformation getPatientInfo(){
        return info;
    }
    /**
     * This method gets the Medical History by using the PatientInformation getMedicalHistory method
     * @return Returns the MedicalHistory for access by using PatientInformation getMedicalHistory method 
     */
    public MedicalHistory getMedicalHistory(){
        return info.getMedicalHistory();
    }
    /**
     * This method returns the list of treatment records for use by this class
     * @return Returns a list of treatment records using the PatientInformation getTreatmentRecord method 
     */
    public List<TreatmentRecord> getTreatmentRecords(){
        return info.getTreatmentRecords();
    }
    /**
     * This method returns the newest treatment record for use in this class
     * @return Returns the newest treatmentRecord via the PatientInformation getNewestTreatment 
     */
    public TreatmentRecord getNewestTreatment(){
    	return info.getNewestTreatment();
    }
}